/*
 * Copyright (c) 2003-2010, Live Media Pty. Ltd.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright notice, this list of
 *     conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright notice, this list of
 *     conditions and the following disclaimer in the documentation and/or other materials
 *     provided with the distribution.
 *  3. Neither the name of Live Media nor the names of its contributors may be used to endorse
 *     or promote products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.colony.networkvm.machine;

import java.util.Stack;

/**
 * A NvmStack is a dual stack of objects and object types.  Both the
 * type and the id are stored on the stack.  
 */
public class NvmStack
{	
	public static final String TYPENAME = "stack";
	
	private Stack _stack;

	public NvmStack(  )
	{
		_stack = new Stack();
	}
	
	public void push( int id, Object o )
	{
		NvmStackElement element = new NvmStackElement();
		element.o = o;
		element.id = id;
		
		_stack.push( element );
	}

	public Object pop()
	{
		NvmStackElement element = (NvmStackElement) _stack.pop();
		return element.o;
	}
	
	public int peekId()
	{
		NvmStackElement element = (NvmStackElement) _stack.peek();
		return element.id;
	}
	
	public Object peek()
	{
		NvmStackElement element = (NvmStackElement) _stack.peek();
		return element.o;
	}
	
	public int size()
	{
		return _stack.size();
	}
	
	public boolean empty()
	{
		return _stack.empty();
	}
	
	private static class NvmStackElement
	{
		public Object o;
		public int id;
	}
}
